<?php
/*
 * 手机客户端 提交余额退款接口
 * 传入参数 
 * 2013-12-02
 */
include "inc/public_header.php";

include "func/user.php";				//用户信息处理函数
include "func/recharge.php";			//用户账户数据处理函数


//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键

$reJson = array(); //构建返回值

$remarks	= $_REQUEST["remarks"];		//备注
$money		= $_REQUEST["money"];		//金额
$cardno		= $_REQUEST["cardno"];		//卡号
$bank		= $_REQUEST["bank"];		//银行名
$subbranch	= $_REQUEST["subbranch"];	//支行名称
$province	= $_REQUEST["province"];	//开户所在省市
$city		= $_REQUEST["city"];		//开户城市
$name		= $_REQUEST["name"];		//开户人姓名

if(!isset($money) || !is_numeric($money)){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"请填写正确的退款金额"));
	die;
}
if(!$cardno){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"请填写银行卡号"));
	die;
}
if(!$bank){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"请填写开户行名称"));
	die;
}
if(!$name){
	echo json_encode(array("success"=>"0","errCode"=>"-1","msg"=>"请填写开户人姓名"));
	die;
}
if($subbranch){
	$subbranch = " ".$subbranch;
}

//获取最新余额
$yue = recharge_getyue($uid);
if($yue<$money){
	echo json_encode(array("success"=>"2","errCode"=>"-1","msg"=>"退款余额不足"));
	die;
}
//提交退款申请
$sql = "
			insert into user_account(payment_typeid,uid,amount,add_time,user_note,process_type,pay_province,pay_city,pay_bank,pay_cardno,pay_cardname,pay_mobile) values(
			'chinapay','".$uid."','".$money."',now(),'".$remarks."',1,'".$province."','".$city."','".$bank.$subbranch."','".$cardno."','".$name."','".$uInfoArr["uid"]."')
		";
$db->query($sql);

$reJson["success"] = "1"; //标记操作成功

echo json_encode($reJson);
?>